import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:scan/scan.dart';
// import 'package:images_picker/images_picker.dart';
import 'package:flutter_screenutil/screenutil.dart';
class QRScanPage extends StatefulWidget {
  @override
  _QRScanPageState createState() => _QRScanPageState();
}

class _QRScanPageState extends State<QRScanPage> {
  String _platformVersion = 'Unknown';

  ScanController controller = ScanController();
  String qrcode = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      platformVersion = await Scan.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }
  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.landscapeRight
    ]);
    ScreenUtil.init(context,width:1600 ,height:900 );
    return Scaffold(
      body: Stack(
        children: [
          Container(
            width:ScreenUtil.screenWidth,
            height:ScreenUtil.screenHeight,
            child: ScanView(
              controller: controller,
              scanAreaScale: .7,
              scanLineColor: Colors.red,
              onCapture: (data) {
                Navigator.of(context).pop(data);
              },
            ),
          ),
          Positioned(
              left: ScreenUtil().setWidth(260),
              top: ScreenUtil().setWidth(1180),
              child: Container(
                child:Text("请将二维码放入框内，即可自动扫描",style: TextStyle(fontSize: ScreenUtil().setSp(65),color: Colors.white),) ,
              )
          ),
        ],
      ),
    );
  }
}
